import * as types from '../action-types'
import {Home} from '../types'
import {Action} from '../actions/home'
let initState:Home = {
  category: 'all',
  sliders:[],
  lessons:{
    hasMore:true,
    list:[],
    offset:0,
    limit:5,
    loading:false

  }
}
export default function (state:Home = initState, action:Action) {
  switch(action.type){
    case types.SET_CATEGORY:
      return {...state,category: action.payload} 
    case types.SET_SLIDERS:
      return {...state,sliders: action.payload} 
    case types.SET_LOADING:
      return {...state,lessons:{...state.lessons,loading:true}} 
    case types.SET_LESSONS:
      return {...state,lessons:{...state.lessons,hasMore:action.payload.hasMore,
      list:[...state.lessons.list,...action.payload.list],
      offset:state.lessons.offset+action.payload.list.length,
      loading:false
      }
    }
    case types.REFRESH_LESSONS:
      return {...state,lessons:{...state.lessons,hasMore:action.payload.hasMore,
      list:action.payload.list,
      offset:action.payload.list.length,
      loading:false
      }
    }  
    default:
      return state
  }
}